<template>
  <div>
    <h1 style="margin:20px 0;font-size:25px;font-weight:600;">案例列表</h1>
    <el-table :data="tableData.filter(data => !search || data.title.toLowerCase().includes(search.toLowerCase()))"
      style="width: 100%">
      <el-table-column label="日期" prop="updateTime">
      </el-table-column>
      <el-table-column label="标题" prop="title">
      </el-table-column>
      <el-table-column align="right">
        <template slot="header" slot-scope="scope">
          <el-input v-model="search" size="medium " placeholder="输入关键字搜索" />
        </template>
        <template slot-scope="scope">
          <el-button size="medium " @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="medium " type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pageBox">
      <el-pagination background layout="prev, pager, next" :page-size="30" :total=total @current-change="getpage">
      </el-pagination>
    </div>
  </div>

</template>

<script>
export default {
  name: 'List',
  data () {
    return {
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        title: '上海市普陀区金沙江路 1518 弄上海市普陀区金沙江路 1518 弄上海市普陀区金沙江路 1518 弄上海市普陀区金沙江路 1518 弄'
      }],
      total: 0,
      search: ''
    }
  },
  methods: {
    handleEdit (index, row) {
      this.$router.push({
        path: '/AdminEdit',
        query: {
          name: 'Case',
          id: row.id
        }
      })
    },
    handleDelete (index, row) {
      this.open1(index, row)
    },
    open1 (index, row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios({
          method: 'get',
          url: '/success/delete?id=' + row.id
        }).then((res) => {
          this.tableData.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    getCaseList () {
      this.$axios({
        method: 'get',
        url: '/success/select?page=1&pageSize=30'
      }).then((res) => {
        if (res.status === 200) {
          this.tableData = res.data.data.rows
          this.total = res.data.data.records
        }
      })
    },
    getpage (e) {
      this.$axios({
        method: 'get',
        url: '/success/select?page=' + e + '&pageSize=30'
      }).then((res) => {
        if (res.status === 200) {
          this.tableData = res.data.data.rows
          this.total = res.data.data.records
        }
      })
    }
  },
  mounted () {
    this.getCaseList()
  }
}
</script>

<style scoped>
.el-table {
  font-size: 18px;
}
.btn {
  margin: 10px 0;
  float: left;
  font-size: 16px;
}
</style>
